using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VFSEGROE
    {
        public DataRow Convert2FSEGROE(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryFSEGROE(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["FSEMANDANT"] = " ".PadRight(2 ); 
         dwReturn["FSEGROES"] = " ".PadRight(7 ); 
         dwReturn["FSEAENZL"] = " ".PadRight(0 ); 
         dwReturn["FSEAENB"] = " ".PadRight(8 ); 
         dwReturn["FSEAEND"] = " ".PadRight(0 ); 
         dwReturn["FSENEUB"] = " ".PadRight(8 ); 
         dwReturn["FSENEUD"] = " ".PadRight(0 ); 
         dwReturn["FSEGRBEZ"] = " ".PadRight(20 ); 
         dwReturn["FSEVERBR"] = " ".PadRight(0 ); 
         dwReturn["FSEMEVB"] = " ".PadRight(3 ); 
         dwReturn["FSEVBGRP"] = " ".PadRight(1 ); 
         dwReturn["FSEVBFKT"] = " ".PadRight(12 ); 
         dwReturn["FSEDURCHM"] = " ".PadRight(0 ); 
         dwReturn["FSEDMME"] = " ".PadRight(3 ); 
         dwReturn["FSEDMGRP"] = " ".PadRight(1 ); 
         dwReturn["FSEDMFKT"] = " ".PadRight(12 ); 
         dwReturn["FSELAENGE"] = " ".PadRight(0 ); 
         dwReturn["FSELAEME"] = " ".PadRight(3 ); 
         dwReturn["FSELAEGRP"] = " ".PadRight(1 ); 
         dwReturn["FSELAEFKT"] = " ".PadRight(12 ); 
         dwReturn["FSEBREITE"] = " ".PadRight(0 ); 
         dwReturn["FSEBRTME"] = " ".PadRight(3 ); 
         dwReturn["FSEBRTGRP"] = " ".PadRight(1 ); 
         dwReturn["FSEBRTFKT"] = " ".PadRight(12 ); 
         dwReturn["FSEHOEHE"] = " ".PadRight(0 ); 
         dwReturn["FSEHOEME"] = " ".PadRight(3 ); 
         dwReturn["FSEHOEGRP"] = " ".PadRight(1 ); 
         dwReturn["FSEHOEFKT"] = " ".PadRight(12 ); 
         dwReturn["FSELAND1"] = " ".PadRight(3 ); 
         dwReturn["FSEAWERT1"] = " ".PadRight(7 ); 
         dwReturn["FSELAND2"] = " ".PadRight(3 ); 
         dwReturn["FSEAWERT2"] = " ".PadRight(7 ); 
         dwReturn["FSELAND3"] = " ".PadRight(3 ); 
         dwReturn["FSEAWERT3"] = " ".PadRight(7 ); 
         dwReturn["FSELAND4"] = " ".PadRight(3 ); 
         dwReturn["FSEAWERT4"] = " ".PadRight(7 ); 
         dwReturn["FSELAND5"] = " ".PadRight(3 ); 
         dwReturn["FSEAWERT5"] = " ".PadRight(7 ); 
         dwReturn["FSEFORMAB"] = " ".PadRight(1 ); 
         dwReturn["FSEFORMRE"] = " ".PadRight(1 ); 
         dwReturn["FSEFORMLS"] = " ".PadRight(1 ); 
         dwReturn["FSEFILLER"] = " ".PadRight(42 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapFSEGROE(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveFSEGROE(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryFSEGROE(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapFSEGROE(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertFSEGROE(dwLocal, ITXDBVERSION);
            }
            UpdateFSEGROE(dwLocal);
        }
        public void InsertFSEGROE(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO FSEGROE(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryFSEGROE(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM FSEGROE WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM FSEGROE  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "FSEGROE";
            Return = Result;
            return Return;
        }
        public void DeleteFSEGROE(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM FSEGROE   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateFSEGROE(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE FSEGROE SET "
                    +"FSEMANDANT= :FSEMANDANT,"
                    +"FSEGROES= :FSEGROES,"
                    +"FSEAENZL= :FSEAENZL,"
                    +"FSEAENB= :FSEAENB,"
                    +"FSEAEND= :FSEAEND,"
                    +"FSENEUB= :FSENEUB,"
                    +"FSENEUD= :FSENEUD,"
                    +"FSEGRBEZ= :FSEGRBEZ,"
                    +"FSEVERBR= :FSEVERBR,"
                    +"FSEMEVB= :FSEMEVB,"
                    +"FSEVBGRP= :FSEVBGRP,"
                    +"FSEVBFKT= :FSEVBFKT,"
                    +"FSEDURCHM= :FSEDURCHM,"
                    +"FSEDMME= :FSEDMME,"
                    +"FSEDMGRP= :FSEDMGRP,"
                    +"FSEDMFKT= :FSEDMFKT,"
                    +"FSELAENGE= :FSELAENGE,"
                    +"FSELAEME= :FSELAEME,"
                    +"FSELAEGRP= :FSELAEGRP,"
                    +"FSELAEFKT= :FSELAEFKT,"
                    +"FSEBREITE= :FSEBREITE,"
                    +"FSEBRTME= :FSEBRTME,"
                    +"FSEBRTGRP= :FSEBRTGRP,"
                    +"FSEBRTFKT= :FSEBRTFKT,"
                    +"FSEHOEHE= :FSEHOEHE,"
                    +"FSEHOEME= :FSEHOEME,"
                    +"FSEHOEGRP= :FSEHOEGRP,"
                    +"FSEHOEFKT= :FSEHOEFKT,"
                    +"FSELAND1= :FSELAND1,"
                    +"FSEAWERT1= :FSEAWERT1,"
                    +"FSELAND2= :FSELAND2,"
                    +"FSEAWERT2= :FSEAWERT2,"
                    +"FSELAND3= :FSELAND3,"
                    +"FSEAWERT3= :FSEAWERT3,"
                    +"FSELAND4= :FSELAND4,"
                    +"FSEAWERT4= :FSEAWERT4,"
                    +"FSELAND5= :FSELAND5,"
                    +"FSEAWERT5= :FSEAWERT5,"
                    +"FSEFORMAB= :FSEFORMAB,"
                    +"FSEFORMRE= :FSEFORMRE,"
                    +"FSEFORMLS= :FSEFORMLS,"
                    +"FSEFILLER= :FSEFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("FSEMANDANT", OracleType.NVarChar).Value = dwData["FSEMANDANT"].ToString(); 
          or1.Parameters.Add("FSEGROES", OracleType.NVarChar).Value = dwData["FSEGROES"].ToString(); 
          or1.Parameters.Add("FSEAENZL", OracleType.NVarChar).Value = dwData["FSEAENZL"].ToString(); 
          or1.Parameters.Add("FSEAENB", OracleType.NVarChar).Value = dwData["FSEAENB"].ToString(); 
          or1.Parameters.Add("FSEAEND", OracleType.NVarChar).Value = dwData["FSEAEND"].ToString(); 
          or1.Parameters.Add("FSENEUB", OracleType.NVarChar).Value = dwData["FSENEUB"].ToString(); 
          or1.Parameters.Add("FSENEUD", OracleType.NVarChar).Value = dwData["FSENEUD"].ToString(); 
          or1.Parameters.Add("FSEGRBEZ", OracleType.NVarChar).Value = dwData["FSEGRBEZ"].ToString(); 
          or1.Parameters.Add("FSEVERBR", OracleType.NVarChar).Value = dwData["FSEVERBR"].ToString(); 
          or1.Parameters.Add("FSEMEVB", OracleType.NVarChar).Value = dwData["FSEMEVB"].ToString(); 
          or1.Parameters.Add("FSEVBGRP", OracleType.NVarChar).Value = dwData["FSEVBGRP"].ToString(); 
          or1.Parameters.Add("FSEVBFKT", OracleType.NVarChar).Value = dwData["FSEVBFKT"].ToString(); 
          or1.Parameters.Add("FSEDURCHM", OracleType.NVarChar).Value = dwData["FSEDURCHM"].ToString(); 
          or1.Parameters.Add("FSEDMME", OracleType.NVarChar).Value = dwData["FSEDMME"].ToString(); 
          or1.Parameters.Add("FSEDMGRP", OracleType.NVarChar).Value = dwData["FSEDMGRP"].ToString(); 
          or1.Parameters.Add("FSEDMFKT", OracleType.NVarChar).Value = dwData["FSEDMFKT"].ToString(); 
          or1.Parameters.Add("FSELAENGE", OracleType.NVarChar).Value = dwData["FSELAENGE"].ToString(); 
          or1.Parameters.Add("FSELAEME", OracleType.NVarChar).Value = dwData["FSELAEME"].ToString(); 
          or1.Parameters.Add("FSELAEGRP", OracleType.NVarChar).Value = dwData["FSELAEGRP"].ToString(); 
          or1.Parameters.Add("FSELAEFKT", OracleType.NVarChar).Value = dwData["FSELAEFKT"].ToString(); 
          or1.Parameters.Add("FSEBREITE", OracleType.NVarChar).Value = dwData["FSEBREITE"].ToString(); 
          or1.Parameters.Add("FSEBRTME", OracleType.NVarChar).Value = dwData["FSEBRTME"].ToString(); 
          or1.Parameters.Add("FSEBRTGRP", OracleType.NVarChar).Value = dwData["FSEBRTGRP"].ToString(); 
          or1.Parameters.Add("FSEBRTFKT", OracleType.NVarChar).Value = dwData["FSEBRTFKT"].ToString(); 
          or1.Parameters.Add("FSEHOEHE", OracleType.NVarChar).Value = dwData["FSEHOEHE"].ToString(); 
          or1.Parameters.Add("FSEHOEME", OracleType.NVarChar).Value = dwData["FSEHOEME"].ToString(); 
          or1.Parameters.Add("FSEHOEGRP", OracleType.NVarChar).Value = dwData["FSEHOEGRP"].ToString(); 
          or1.Parameters.Add("FSEHOEFKT", OracleType.NVarChar).Value = dwData["FSEHOEFKT"].ToString(); 
          or1.Parameters.Add("FSELAND1", OracleType.NVarChar).Value = dwData["FSELAND1"].ToString(); 
          or1.Parameters.Add("FSEAWERT1", OracleType.NVarChar).Value = dwData["FSEAWERT1"].ToString(); 
          or1.Parameters.Add("FSELAND2", OracleType.NVarChar).Value = dwData["FSELAND2"].ToString(); 
          or1.Parameters.Add("FSEAWERT2", OracleType.NVarChar).Value = dwData["FSEAWERT2"].ToString(); 
          or1.Parameters.Add("FSELAND3", OracleType.NVarChar).Value = dwData["FSELAND3"].ToString(); 
          or1.Parameters.Add("FSEAWERT3", OracleType.NVarChar).Value = dwData["FSEAWERT3"].ToString(); 
          or1.Parameters.Add("FSELAND4", OracleType.NVarChar).Value = dwData["FSELAND4"].ToString(); 
          or1.Parameters.Add("FSEAWERT4", OracleType.NVarChar).Value = dwData["FSEAWERT4"].ToString(); 
          or1.Parameters.Add("FSELAND5", OracleType.NVarChar).Value = dwData["FSELAND5"].ToString(); 
          or1.Parameters.Add("FSEAWERT5", OracleType.NVarChar).Value = dwData["FSEAWERT5"].ToString(); 
          or1.Parameters.Add("FSEFORMAB", OracleType.NVarChar).Value = dwData["FSEFORMAB"].ToString(); 
          or1.Parameters.Add("FSEFORMRE", OracleType.NVarChar).Value = dwData["FSEFORMRE"].ToString(); 
          or1.Parameters.Add("FSEFORMLS", OracleType.NVarChar).Value = dwData["FSEFORMLS"].ToString(); 
          or1.Parameters.Add("FSEFILLER", OracleType.NVarChar).Value = dwData["FSEFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
